package org.neuedu.fly.web;

import org.neuedu.fly.entity.User;
import org.neuedu.fly.entity.vo.ResponseEntity;
import org.neuedu.fly.service.ReplyService;
import org.neuedu.fly.util.SysUtil;

import javax.servlet.annotation.WebServlet;

@WebServlet("/reply/*")
public class ReplyServlet extends BaseServlet {
    private ReplyService replyService = new ReplyService();

    public ResponseEntity replyList(){
        return replyService.replyList();
    }

    public ResponseEntity findReplyByUserId(){
//        User user = (User) request.getSession().getAttribute(SysUtil.CURRENT_USER);
//        int userId = user.getId();
        int userId = Integer.parseInt(request.getParameter("userId"));
        return replyService.findReplyByUserId(userId);
    }

    public ResponseEntity findReplyByPostId(){
        String postId = request.getParameter("postId");
        return replyService.findReplyByPostId(postId);
    }

    public ResponseEntity reply(){
        String postId = request.getParameter("postId");
        String replyContext = request.getParameter("replyContext");
        String userId = request.getParameter("userId");
        return replyService.reply(postId,replyContext,userId);
    }

    public ResponseEntity delReplyByReplyId(){
        String replyId = request.getParameter("replyId");
        return replyService.delReplyByReplyId(replyId);
    }

    public ResponseEntity delAllReply(){
        User user = (User) request.getSession().getAttribute(SysUtil.CURRENT_USER);
        int userId = user.getId();
        return  replyService.delReplyByUserId(userId);
    }
}
